package com.gebiafu.controller;

import com.gebiafu.pojo.User;
import com.gebiafu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * title: UserController
 * author: Gebiafu
 * date: 2021/07/02 13:30
 * 用户控制器,实现用户控制逻辑
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 注册方法
     * 服务端校验重复密码,因为客户端js可以关闭
     * @param user 注册信息
     * @param repeatPassword 重复密码
     * @return
     */
    @RequestMapping("/register")
    public String register(User user,String repeatPassword){
        try {
            userService.addUser(user,repeatPassword);
            //z注册成功后,响应重定向到登陆页面,去登录
            return "redirect:/";
        } catch (Exception e) {
            //注册失败,响应重定向到注册页面,提示错误
            return "redirect:/toRegister?error?";
        }
    }
}
